﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Raven.Client.Indexes;
using RavenAcessLayer;
using rv = RavenAcessLayer;
using dts =ControlIP.DataTypes;

namespace ControlIp.Bussiness
{
    public class Entry
    {

        public static bool AddEntry( dts.DomainObjects.Entry tEntry)
        {
            DataObjectOperationResult resul;
            try
            {
                using (var db = rv.DataContext.Db.Session)
                {
                   resul= tEntry.Save();

                }

            }
            catch (Exception ex)
            {
                
                throw ex;
            }

            return resul.Success;
        }

        public  static  List<dts.DomainObjects.Entry> GetEntryByUser(String user )
        {
            
            List<dts.DomainObjects.Entry> list = new List<ControlIP.DataTypes.DomainObjects.Entry>();
            DataObjectOperationResult resul;
            try
            {

                //DataContext.Db.DocumentStore.DatabaseCommands
                //    .PutIndex("ThingsByName", new IndexDefinitionBuilder<Thing>
                //    {
                //        Map = things => things.Select(x => new { x.Name })
                //    }, true);

                using (var db = rv.DataContext.Db.Session)
                {
                    //var orders = db.Query<NormalizedThing>()
                    //    .Where(thing => 
                    //        thing.Items.Any(item => 
                    //            item.Product == "GI Joe"));

                   list = db.Query<dts.DomainObjects.Entry>().Where(x => x.User.Username.Equals("vviana")).ToList();


                    //list = entryByUser.ToList();
                }

            }
            catch (Exception ex)
            {
                
                throw ex;
            }

            return list;


        } 

    }
}
